package com.ww.byteBuf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import java.nio.charset.Charset;

/**
 * @ClassName:
 * @author:
 * @Description:
 * @Date
 **/
// byteBuf的get和set方法
public class ByteBuf03 {
    public static void main(String[] args) {
        Charset charset = Charset.forName("UTF-8");
        ByteBuf buf = Unpooled.copiedBuffer("Netty in action rocks.", charset);
        System.out.println((char) buf.getByte(0));
        //存储当前readerIndex和writerIndex
        int readerIndex = buf.readerIndex();
        int writerIndex = buf.writerIndex();
        //将索引0处的字节更新为字符B
        buf.setByte(2, (byte) 'B');
        System.out.println((char) buf.getByte(2));
        //这些操作不会改变索引位置，断言会成功
        assert readerIndex == buf.readerIndex();
        assert writerIndex == buf.writerIndex();
    }
}
